import 'package:flutter/material.dart';
import 'package:moose_app/ui/values/values.dart';

import 'circle/circle_content.dart';
import 'square/square_content.dart';

class ATHDiscoveryScreen extends StatefulWidget {
  @override
  _ATHDiscoveryScreenState createState() => _ATHDiscoveryScreenState();
}

class _ATHDiscoveryScreenState extends State<ATHDiscoveryScreen>
    with SingleTickerProviderStateMixin, AutomaticKeepAliveClientMixin {
  TabController _tabController;

  List<String> _tabsText = ["广场", "圈子"];

  List<Tab> _tabs = [];

  @override
  void initState() {
    super.initState();
    _tabsText.forEach((element) {
      _tabs.add(Tab(
        text: element,
      ));
    });

    _tabController =
        TabController(initialIndex: 0, length: _tabs.length, vsync: this);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: _buildTabBar(),
        centerTitle: false,
      ),
      body: _buildTabBarView(),
    );
  }

  TabBar _buildTabBar() {
    return TabBar(
      isScrollable: true,
      controller: _tabController,
      tabs: _tabs,
      enableFeedback: false,
      overlayColor: MaterialStateProperty.all(Colors.transparent),
      indicator: UnderlineTabIndicator(
        borderSide: const BorderSide(width: 0, color: Colors.transparent),
      ),
      labelColor: Colors.white,
      labelStyle: TextStyle(fontSize: kFontSize36, fontWeight: FontWeight.bold),
      unselectedLabelStyle: TextStyle(fontSize: kFontSize32),
      unselectedLabelColor: kColor33,
    );
  }

  TabBarView _buildTabBarView() {
    List<Widget> tabContents = [];
    for (int index = 0; index < _tabsText.length; index++) {
      if (index == 0) {
        tabContents.add(ATHSquareContent());
      } else if (index == 1) {
        tabContents.add(ATHCircleContent());
      }
    }
    return TabBarView(controller: _tabController, children: tabContents);
  }

  @override
  bool get wantKeepAlive => true;
}
